import 'package:flutter/material.dart';

import '../../flutter_common.dart';
import '../../util/context_extension.dart';

class LeftRightTextItem extends StatelessWidget {
  final String title;
  final String? content;
  final TextStyle? titleStyle;
  final TextStyle? contentStyle;
  // 是否展示下划线
  final bool showLine;
  final double lineLeftPadding;
  final double textLeftPadding;
  final double minHeight;
  final Color? backgroundColor;
  final EdgeInsetsGeometry padding;
  final int maxLine;

  const LeftRightTextItem(
      {Key? key,
        required this.title,
        this.content,
        this.titleStyle,
        this.contentStyle,
        this.lineLeftPadding = 0,
        this.textLeftPadding = 15,
        this.minHeight = 50,
        this.maxLine = 1,
        this.padding = const EdgeInsets.symmetric(vertical: 15),
        this.backgroundColor,
        this.showLine = false})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    Widget body = Stack(
      alignment: Alignment.centerLeft,
      children: [
        Padding(padding: padding,
          child: Row(
            children: [
              SizedBox(width: textLeftPadding),
              Text(
                title,
                style: titleStyle??TextStyle(fontSize: fontSize28, color: Color(0xFF333333)),
              ),
              const SizedBox(width: 15,),
              Expanded(
                  child: Align(
                    alignment: Alignment.centerRight,
                    child: Text(
                      content ?? '',
                      maxLines: maxLine,
                      softWrap: true,
                      overflow: maxLine == 1 ? TextOverflow.ellipsis : null,
                      style: contentStyle??TextStyle(fontSize: fontSize28,color: Color(0xFF111111)),
                      textAlign: TextAlign.right,
                    ),
                  )),
              const SizedBox(width: 15),
            ],
          ),
        ),
        if (showLine)
          Positioned(
            child: FxTheme().line,
            left: lineLeftPadding,
            bottom: 0,
            right: 0,
          )
      ],
    );
    return Container(
        constraints: BoxConstraints(minHeight: minHeight),
        width: double.infinity,
        color: backgroundColor,
        child: body);
  }
}
